import { http } from '@/utils/http'

interface News {
  id?: number
  title: string
  source: string
  imageUrl: string
  link: string
  createdTime?: string
  updateTime?: string
}

// 新增新闻
export const insertNews = (data: News) => {
  return uni.request({
    url: '/news/insert-news',
    method: 'POST',
    data,
    header: {
      'Content-Type': 'application/json',
      token: uni.getStorageSync('token'),
    },
  })
}

// 分页查询新闻列表
export const getNewsList = (pageNum: number = 1, pageSize: number = 5) => {
  return uni.request({
    url: `/news/queryNewsByPage/${pageNum}/${pageSize}`,
    method: 'POST',
    header: {
      'Content-Type': 'application/json',
      token: uni.getStorageSync('token'),
    },
  })
}

// 更新新闻
export const updateNews = (data: News) => {
  return uni.request({
    url: '/news/updateNews',
    method: 'POST',
    data,
    header: {
      'Content-Type': 'application/json',
      token: uni.getStorageSync('token'),
    },
  })
}

// 删除新闻
export const deleteNews = (id: number) => {
  return uni.request({
    url: `/news/deleteNews/${id}`,
    method: 'POST',
    header: {
      token: uni.getStorageSync('token'),
    },
  })
}
